﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SquidConsult.DAL;
using System.Data;

namespace SquidConsult.BLL
{

    public class ConsultantBL : PeopleBL
    {
        private static bool generateReportID = true;
        private static System.Guid reportID;
        private static decimal totalExpense = 0;
        private ConsultantDS consultantDS = new ConsultantDS();

        #region Add new Report
        public void SetExpense(System.DateTime ExpenseDate, string Location, string Description, string Expense, string ReceiptPath)
        {
            if (generateReportID)
            {
                reportID = System.Guid.NewGuid();
                totalExpense = 0;
            }
            totalExpense += decimal.Parse(Expense);
            consultantDS.SetExpense(reportID, System.Guid.NewGuid(), ExpenseDate, Location, Description, decimal.Parse(Expense), ReceiptPath);
            generateReportID = false;
        }

        public void SetReport(System.Guid ConsultantId, string supervisor)
        {
             consultantDS.SetReport(reportID, ConsultantId, System.DateTime.Now, totalExpense, supervisor);
        }

        #endregion 

        #region Get Reports 
        public IQueryable GetAllReport(Guid consultantId)
        {
            return consultantDS.GetAllReport(consultantId);
        }

        public IQueryable GetStatusReport(Guid consultantId, string status)
        {
            return consultantDS.GetStatusReport(consultantId, status);
        }

        public IQueryable GetSupervisorName(Guid consultantId)
        {
            return consultantDS.GetSupervisorName(consultantId);
        }
        #endregion

        #region Convert Currency
        public double GetCurrency(double amount, string currency)
        {
            Sample.Convertor.CurrencyConvertorSoapClient convertor = new Sample.Convertor.CurrencyConvertorSoapClient("CurrencyConvertorSoap");
            if (currency == "USD")
                return amount * convertor.ConversionRate(Sample.Convertor.Currency.USD, Sample.Convertor.Currency.AUD);
            else if (currency == "CNY")
                return amount * convertor.ConversionRate(Sample.Convertor.Currency.CNY, Sample.Convertor.Currency.AUD);
            else
                return amount;
           
        }

        #endregion 

        #region Set and Get ReportId 

        public bool GenerateReportID
        {
            set
            {
                generateReportID = value;
            }
            get
            {
                return generateReportID;
            }
        }

        public System.Guid ReportID
        {
            set
            {
                reportID = value;
            }
            get
            {
                return reportID;
            }
        }
        #endregion
    }
}
